﻿namespace ChessToys
{
    using System;

    /// <summary>
    /// A move represents a start postion and a end position for moving a piece.
    /// </summary>
    public class Move : AbstractPair<Position, Position>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Move"/>.
        /// </summary>
        /// <param name="start">The start position.</param>
        /// <param name="end">The end position.</param>
        public Move(Position start, Position end)
            :base(start, end)
        {
        }

        /// <summary>
        /// Gets the start position.
        /// </summary>
        /// <value>The start position.</value>
        public Position Start
        {
            get { return First; }
        }

        /// <summary>
        /// Gets the end position.
        /// </summary>
        /// <value>The end position.</value>
        public Position End
        {
            get { return Second; }
        }

        /// <inheritdoc />
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return true;
            }
            if (obj.GetType() != typeof(Move))
            {
                return false;
            }
            Move other = obj as Move;
            return Start.Equals(other.Start) && End.Equals(other.End);
        }

        public override int GetHashCode()
        {
            return 31 * Start.GetHashCode() + 51 * End.GetHashCode();
        }

        /// <inheritdoc />
        public override String ToString()
        {
            return String.Format("{0} -> {1}", Start, End);
        }

        public String ToString(Board board)
        {
            return String.Format("{0} -> {1}", Start.ToString(board), End.ToString(board));
        }
    }
}
